import { createConnection } from "typeorm";
import { User } from "./entity/User";

createConnection({
  type: "mysql",
  host: "localhost",
  port: 3306,
  username: "root",
  password: "aaaa",
  database: "test_db",
  entities: [__dirname + "/entity/*.ts"],
  synchronize: true
})
  .then(async connection => {
    // 这里可以写实体操作相关的代码
    const repository = connection.manager.getRepository(User);
    const users = await repository.findOne(1);
    console.log(users);
  })
  .catch(error => console.log(error));